package com.elitel.frame.web.serverinfo.controller;

import com.elitel.common.core.domain.JsonResult;
import com.elitel.frame.web.serverinfo.dto.ServerInfoDTO;
import com.elitel.frame.web.serverinfo.service.ServerInfoService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author m
 */
@RestController
@RequestMapping("serverInfo")
public class ServerInfoController {
    @Resource
    private ServerInfoService serverInfoService;

    @PostMapping("save")
    public JsonResult<?> save(@RequestBody ServerInfoDTO dto) throws Exception {
        return JsonResult.success(serverInfoService.saveData(dto));
    }

    @GetMapping("updateCacheStatus")
    public JsonResult<?> updateCacheStatus(String serverId, String cacheFlag) {
        String msg = serverInfoService.updateCacheStatus(serverId, cacheFlag);
        if ("ok".equals(msg)) {
            return JsonResult.success(msg);
        }
        return JsonResult.error(msg);
    }

    @GetMapping("selectByServerId")
    public JsonResult<?> selectByServerId(String serverId) {
        return JsonResult.success(serverInfoService.selectByServerId(serverId));
    }
}
